// Decompiled by Jad v1.5.8g. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://www.kpdus.com/jad.html
// Decompiler options: packimports(3)
// Source File Name:   Tyg_txQuery1.java


//Changing this program to allow update

package MaintMenu.VenPricingUpdMasterFiles;

import javax.swing.*;
import java.sql.*;

public class test2bak
{

    public test2bak(String poid, String isCapa, String boName)
    {
        try
        {
            Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
            String dataSourceName = "dbLI";
            String dbURL = (new StringBuilder()).append("jdbc:odbc:").append(dataSourceName).toString();
            Connection con = DriverManager.getConnection(dbURL, "", "");
            Statement st = con.createStatement();
            Statement st2 = con.createStatement();
            Statement st3 = con.createStatement();
            Statement st4 = con.createStatement();
            Statement st5 = con.createStatement();
            String dataSourceName6 = "dbBL";
            String dbURL6 = (new StringBuilder()).append("jdbc:odbc:").append(dataSourceName6).toString();
            Connection con6 = DriverManager.getConnection(dbURL6, "", "");
            Statement st6 = con6.createStatement();
            Statement st7 = con6.createStatement();
            Statement st8 = con6.createStatement();
            if(isCapa.equals(""))
                isCapa = "C";
            try
            {

                //step to find out the DNK PO# (ie MR130512LIgn) from UAPO# (ie 165570 entered)   from tblpurchaseorders table
                st.execute("select [ref#] as ref from tblpurchaseorders where poid = " + poid + ";");
                ResultSet rs = st.getResultSet();
                String container = null;
                if(rs != null)
                {
                    rs.next();
                    container = rs.getString("ref");  //UA PO #  (i.e. MR130530LIdp) as varibal contrainer
                }
                //get detail information about PO from tblpuchaseordertail tablet with UAPO# (i.e. 165570)
                st2.execute("select [part#] as part_no, duedate, invid, quantity, unitprice from tblpurchaseorderdetail where poid = " + poid + ";");
                ResultSet rs2 = st2.getResultSet();
                String duedate = null;
                String duedate1 = null;
                long invid = 0L;
                String part_no = null;
                double quantity = 0.0D;
                double unitprice = 0.0D;
                String description = null;
                String description1 = null;
                if(rs2 != null)
                {
                    rs2.next();
                    duedate = rs2.getString("duedate");
                    duedate1 = duedate.substring(5, 7) + "/" + duedate.substring(8, 10) + "/" + duedate.substring(2, 4);
                    System.out.printf("%s\n", duedate);
                    System.out.printf("%s\n", duedate1);

                    //create an entry in tblcontainerheader in Hicksville
                    st4.execute((new StringBuilder()).append("insert into tblcontainerheader(container,arrival) values ('").append(container).append("',#").append(duedate1).append("#);").toString());
                    st5.execute((new StringBuilder()).append("select * from tblcontainerheader where container = '").append(container).append("';").toString());
                    ResultSet rs5 = st5.getResultSet();

                    System.out.printf("rs5 result: %s\n",rs5);

                    long containerKey = 0L;
//                    if(rs5 != null)
//                    {
//                        rs5.next();
//                        //got container number from st4
//                        containerKey = rs5.getLong("containerkey");
//                    }
                    //
//                    st4.execute("INSERT INTO TBLCONTAINERDETAIL ( CONTAINERKEY, INVID, PN, QTY, RECEIVED ) SELECT " + containerKey + ", INVID, [PART#], quantity, 0 " + "FROM tblpurchaseorderdetail " + "where poid = " + poid + ";");
//                    st4.execute("UPDATE TBLBCN AS A INNER JOIN tblcontainershipped AS B ON A.[PART#]=B.dnk_no SET A.TYG_TX_P = B.PRICE where b.containername='" + container + "';");
//                    st4.execute((new StringBuilder()).append("UPDATE TBLCLN AS A INNER JOIN tblcontainershipped AS B ON A.[PART#]=B.dnk_no SET A.TYG_TX_P = B.PRICE where b.containername='").append(container).append("';").toString());
//                    st4.execute((new StringBuilder()).append("UPDATE TBLHFN AS A INNER JOIN tblcontainershipped AS B ON A.[PART#]=B.dnk_no SET A.TYG_TX_P = B.PRICE where b.containername='").append(container).append("';").toString());
//                    st4.execute((new StringBuilder()).append("UPDATE TBLMRN AS A INNER JOIN tblcontainershipped AS B ON A.[PART#]=B.dnk_no SET A.TYG_TX_P = B.PRICE where b.containername='").append(container).append("';").toString());
//                    st4.execute((new StringBuilder()).append("UPDATE TBLOTN AS A INNER JOIN tblcontainershipped AS B ON A.[PART#]=B.dnk_no SET A.TYG_TX_P = B.PRICE where b.containername='").append(container).append("';").toString());

                    //Below is process if container include BK or bk (i.e. LT130502BKtx)    This allows transfer data from Hicksville to Brooklyn.
                    if(container.indexOf("bk") > 0 || container.indexOf("BK") > 0)
                    {
//                        st6.execute("delete * from tblbc_work;");
//                        st6.execute("delete * from tblbc_temp;");
//                        //create an entry in tblcontainerheader in Brooklyn
//                        st6.execute("insert into tblcontainerheader(containerkey,container,arrival) values (" + containerKey + ", '" + container + "',#" + duedate1 + "#);");
                        //get purchaseorderdetail by poid(i.e. MR130503BKgn) from Hicksville Data
                        st3.execute("select [part#] as part_no, duedate, invid, quantity, unitprice, description from tblpurchaseorderdetail where poid = " + poid + ";");
                        for(ResultSet rs3 = st3.getResultSet(); rs3.next();)
                        {
                            //data read from dbli
                            invid = rs3.getLong("invid");
                            part_no = rs3.getString("part_no");
                            quantity = rs3.getDouble("quantity");
                            unitprice = rs3.getDouble("unitprice");
                            description = rs3.getString("description");
                            description1 = description.replace('\'', ' ');
                            try
                            {
                                //push data from above to dbbl
                                st7.execute("INSERT INTO TBLCONTAINERDETAIL ( CONTAINERKEY, INVID, PN, QTY, RECEIVED ) values(" + containerKey + ", " + invid + ", '" + part_no + "', " + quantity + ", 0);");
                                st8.execute("INSERT INTO TBLBC_WORK ( [PART#], SUPPLIER, TYG_TX, TYG_TX_P, TYG_TX_QP, [TYG_TX#], description ) values('" + part_no + "', 'X', " + quantity + ", " + unitprice + ", " + unitprice + ", null, '" + description1 + "');");
                            }
                            catch(SQLException er) {
                                JOptionPane.showMessageDialog(null, er);

                            }
                        }

//                        st6.execute("INSERT INTO TBLBC_TEMP SELECT * FROM TBLBC_WORK;");
                    }
                }
            }
            catch(SQLException er)
            {
                er.printStackTrace();
                JOptionPane.showMessageDialog(null, er);
            }
            st.close();
            st2.close();
            st3.close();
            st4.close();
            st5.close();
            st6.close();
            st7.close();
            st8.close();
            con.close();
            con6.close();
        }
        catch(Exception e)
        {
            e.printStackTrace();
            JOptionPane.showMessageDialog(null, e);
        }
    }
}
